package cn._51doit.kafka;

import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.common.serialization.StringSerializer;

import java.util.Properties;

/**
 * @create: 2021-10-12 10:18
 * @author: 珠穆朗玛峰顶峰的男人
 * @program: kafka_java_scala
 * 生产者
 **/

public class JavaProperties {
    public static void main(String[] args) {
        //配置kafka参数对象
        Properties properties = new Properties();
        // 连接kafka节点
        properties.setProperty("bootstrap.servers", "doit01:9092,doit02:9092,doit03:9092");
        //指定key序列化方式
        properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        //指定value序列化方式
        properties.setProperty("value.serializer", StringSerializer.class.getName());
        //生产者实例
        KafkaProducer<String, String> producer = new KafkaProducer<String, String>(properties);
        //封装数据
        ProducerRecord<String, String> producerRecord = new ProducerRecord<>("word", "hello flink 666");
        //写数据方法
        producer.send(producerRecord);
        //关闭资源
        producer.close();

    }
}
